﻿using NUnit.Framework;
using Inovout.Descriptors;
using Inovout.Models;

namespace Inovout.Service.Tests.Model
{
    [TestFixture]
    public class IntIdDataObjectTestCase
    {
        private IntIdDataObject testIdValueDataObject_0;
        private IntIdDataObject testIdValueDataObject_1;
        private IntIdDataObject targetIdValueDataObject_0;
        private IntIdDataObject targetIdValueDataObject_1;
        private IntIdDataObject targetIdValueDataObject_2;

        [SetUp]
        public void TestInitialize()
        {
            FieldDescriptor idFieldDescriptor = new TypeDescriptor(typeof(IntIdDataObject)).GetField("id");

            testIdValueDataObject_0 = new IntIdDataObject();
            idFieldDescriptor.SetValue(testIdValueDataObject_0, 0);
            testIdValueDataObject_1 = new IntIdDataObject();
            idFieldDescriptor.SetValue(testIdValueDataObject_1, 1);

            targetIdValueDataObject_0 = new IntIdDataObject();
            idFieldDescriptor.SetValue(targetIdValueDataObject_0, 0);
            targetIdValueDataObject_1 = new IntIdDataObject();
            idFieldDescriptor.SetValue(targetIdValueDataObject_1, 1);
            targetIdValueDataObject_2 = new IntIdDataObject();
            idFieldDescriptor.SetValue(targetIdValueDataObject_2, 2);
        }
        [Test]
        public void EqualsTest()
        {
            bool expected;
            bool actual;
            //0-Null
            expected = false;
            actual = testIdValueDataObject_0.Equals(null);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_0.Equals(null)");


            #region Test_0

            //0
            expected = false;
            actual = testIdValueDataObject_0.Equals(targetIdValueDataObject_0);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_0.Equals(targetIdValueDataObject_0)");

            //1
            expected = false;
            actual = testIdValueDataObject_0.Equals(targetIdValueDataObject_1);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_0.Equals(targetIdValueDataObject_1)");

            //2
            expected = false;
            actual = testIdValueDataObject_0.Equals(targetIdValueDataObject_2);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_0.Equals(targetIdValueDataObject_2)");

            #endregion

            #region Test_1

            //0
            expected = false;
            actual = testIdValueDataObject_1.Equals(targetIdValueDataObject_0);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_1.Equals(targetIdValueDataObject_0");

            //1
            expected = true;
            actual = testIdValueDataObject_1.Equals(targetIdValueDataObject_1);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_1.Equals(targetIdValueDataObject_1)");

            //2
            expected = false;
            actual = testIdValueDataObject_1.Equals(targetIdValueDataObject_2);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_1.Equals(targetIdValueDataObject_2)");

            #endregion
        }

        [Test]
        public void GetHashCodeTest()
        {
            int expected;
            int actual;
            #region Test_0
            expected = (0).GetHashCode();
            actual = testIdValueDataObject_0.GetHashCode();
            Assert.AreNotEqual(expected, actual, "testIdValueDataObject_0.GetHashCode()");
            #endregion

            #region Source_1
            expected = (1).GetHashCode();
            actual = testIdValueDataObject_1.GetHashCode();
            Assert.AreEqual(expected, actual, "testIdValueDataObject_1.GetHashCode()");

            #endregion

        }

        public class IntIdDataObject : DataObject
        {
        }
    }
}
